package com.chengcang.api.modules.login.utils;

import com.chengcang.api.modules.sys.dto.SysUserDTO;
import com.chengcang.api.modules.sys.entity.SysUserEntity;

public class UserHolder {
    private static final ThreadLocal<SysUserDTO> TL = new ThreadLocal<>();

    public static void setUser(SysUserDTO user) {
        TL.set(user);
    }

    public static Long getUserId() {
        return TL.get().getId();
    }

    public static SysUserDTO getUser() {
        return TL.get();
    }

    public static void removeUser() {
        TL.remove();
    }

    public static void switchTenant(Long tenantId, Integer userType,Integer tenantType) {
        SysUserDTO user = TL.get();
        user.setDefaultUserType(userType);
        user.setDefaultTenantId(tenantId);
        user.setTenantType(tenantType);
        TL.set(user);
    }
}
